<template>
  <div class="container">
    <div class="login_box">
      <div class="headPortrait">
        <img src="../assets/portrait.png">
      </div>
      <el-form ref="form" :model="form" label-width="auto" :rules="rules">
        <el-form-item label="" prop="username">
          <el-input v-model="form.username" prefix-icon="el-icon-user-solid">
          </el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input v-model="form.password" prefix-icon="el-icon-lock" show-password></el-input>
        </el-form-item>
      </el-form>
      <div class="login_button">
        <el-button type="primary" @click='login'>登录</el-button>
        <el-button type="info" @click="reset">重置</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入用户密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    login() {
      if (this.form.username === '' || this.form.password === '') {
        this.$message.error('请输入登录信息')
      } else {
        this.$http.post('login', this.form).then(response => {
          if (!response.data.isSuccess) {
            // this.$message.error(response.data.message)
            this.$message({
              message: '用户名或密码错误！',
              type: 'error'
            })
          } else {
            window.sessionStorage.setItem('token', response.data.token)
            // this.$message.success(response.data.message)
            this.$router.push('/BsHome')
          }
        })
      }
    },
    reset() {
      this.form.username = ''
      this.form.password = ''
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  width: 100%;
  background-image: linear-gradient(
    to right,
    rgba(94, 195, 254, 0.6),
    rgba(121, 208, 194, 0.6)
  );
  .login_box {
    width: 600px;
    height: 400px;
    background-color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(202, 202, 202, 0.25);
    .headPortrait {
      width: 150px;
      height: 150px;
      position: absolute;
      left: 50%;
      top: 3%;
      transform: translateX(-50%);
      img {
        width: 100%;
        height: 100%;
      }
    }
    .el-form {
      margin-top: 180px;
      text-align: center;
      /deep/.el-form-item__error {
        left: 35px;
      }
      .el-input {
        width: 540px;
        /deep/ .el-input__inner {
          height: 45px;
          line-height: 45px;
        }
        /deep/ .el-input__prefix {
          line-height: 45px;
          font-size: 18px;
        }
      }
    }
    .login_button {
      float: right;
      margin-right: 30px;
      margin-top: 10px;
      .el-button {
        width: 90px;
        height: 50px;
        font-size: 16px;
        margin-left: 20px;
      }
    }
  }
}
</style>
